//
//  UINavigationController+EMNavi.m
//  ElectronicMall
//
//  Created by 史伟文 on 14/12/22.
//  Copyright (c) 2014年 cczu. All rights reserved.
//

#import "UINavigationController+EMNavi.h"
#import "EMSearchBar.h"
@implementation UINavigationController (EMNavi)

- (void)setNavigationMode: (NSInteger)mode andSubMode: (NSInteger)subMode
{
    if (mode == EMNavigationModeDefault) {
        [self drawDefaultNavigationBar];
    } else if (mode == EMNavigationModeNone){
        [self drawNavigationBarHidden];
    } else {
        [self drawSearchNavigationWithSubMode:subMode];
    }
}
- (void)drawDefaultNavigationBar
{
    self.navigationBarHidden = NO;
    self.navigationBar.barTintColor = RGB(112, 179, 81);
    self.navigationBar.backgroundColor = RGB(112, 179, 81);
    NSDictionary *dict = @{
                           NSForegroundColorAttributeName: [UIColor whiteColor],
                           
                           };
    self.navigationBar.titleTextAttributes = [dict mutableCopy];
    
//    self.navigationBar.tintColor = RGB(112, 79, 81);
    
}
- (void)drawNavigationBarHidden
{
    self.navigationBarHidden = YES;
}
- (void)drawSearchNavigationWithSubMode: (NSInteger)subMode
{
    self.navigationBarHidden = NO;
    
    EMSearchBar *search = [[EMSearchBar alloc] initWithFrame:CGRectMake(55, 3, 160, 24)];
    search.placeholderText = @"please";
    [self.navigationBar addSubview:search];
    
    if (subMode == EMNavigationSearchSubModeLogoAndCity)
    {
        UIImageView *logoImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo_导航"]];
        logoImage.frame = CGRectMake(5, 8, 96, 24);
        [self.navigationBar addSubview:logoImage];
        UIButton *cityButton = [UIButton buttonWithType:UIButtonTypeCustom];
        cityButton.frame = CGRectMake(255, 6, 60, 24);
        [cityButton setImage:[UIImage imageNamed:@"icon_地址选择"] forState:UIControlStateNormal];
        [cityButton setTitle:@"南京" forState:UIControlStateNormal];
        [cityButton setTitleColor:RGB(101, 118, 32) forState:UIControlStateNormal];
        cityButton.titleLabel.font = [UIFont fontWithName:HEITIMEDIUM size:14];
        [self.navigationBar addSubview:cityButton];
    }
    else if (subMode == EMNavigationSearchSubModeLogoAndCancel)
    {
        UIImageView *logoImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo_导航"]];
        logoImage.frame = CGRectMake(5, 8, 96, 18);
        [self.navigationBar addSubview:logoImage];
        UIButton *cityButton = [UIButton buttonWithType:UIButtonTypeCustom];
        cityButton.frame = CGRectMake(255, 6, 60, 24);
        [cityButton setTitle:@"取消" forState:UIControlStateNormal];
        [cityButton setTitleColor:RGB(101, 118, 32) forState:UIControlStateNormal];
        cityButton.titleLabel.font = [UIFont fontWithName:HEITIMEDIUM size:14];
        [self.navigationBar addSubview:cityButton];
    }
    else if (subMode == EMNavigationSearchSubModeCity)
    {
        UIButton *cityButton = [UIButton buttonWithType:UIButtonTypeCustom];
        cityButton.frame = CGRectMake(10, 6, 80, 24);
        [cityButton setTitle:@"当前：南京" forState:UIControlStateNormal];
        [cityButton setTitleColor:RGB(101, 118, 32) forState:UIControlStateNormal];
        cityButton.titleLabel.font = [UIFont fontWithName:HEITIMEDIUM size:14];
        [self.navigationBar addSubview:cityButton];
    }
    else
    {
        UIImageView *logoImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"button_导航_返回_绿"]];
        logoImage.frame = CGRectMake(10, 4, 28, 28);
        [self.navigationBar addSubview:logoImage];
    }
    
    
    
    
}

@end
